package com.api.sw.duban.util;

import jxl.read.biff.Record;
import weaver.conn.RecordSet;
import weaver.general.Util;

import javax.sound.midi.Receiver;
import java.text.SimpleDateFormat;
import java.util.Date;

//绿色  background-color: rgb(227, 246, 216);  正常
//黄色  background-color: rgb(255, 228, 196);
//红色  background-color: rgb(251, 223, 235);  延期
public class dubanTran {
    private final static LogTool log = new LogTool("/log/duban/",false);
    public String getDpartmentnameByid(String departmentid){
        RecordSet re=new RecordSet();
        String departmentname="";
        departmentid= Util.null2String(departmentid).trim();
        if("".equals(departmentid)){
           return departmentname;
        }
        if(departmentid.endsWith(",")){
            departmentid=departmentid.substring(0,departmentid.length()-1);
        }
        String sql="select * from hrmdepartment where id in ("+departmentid+")";
        re.execute(sql);
        while(re.next()){
             departmentname=departmentname+Util.null2String(re.getString("departmentname")).trim()+",";
        }
        if(departmentname.endsWith(",")){
            departmentname=departmentname.substring(0,departmentname.length()-1);
        }
        return departmentname;
    }
    public String getSwDpartmentnameByid(String departmentid){
        RecordSet re=new RecordSet();
        String departmentname="";
        departmentid= Util.null2String(departmentid).trim();
        if("".equals(departmentid)){
            return departmentname;
        }
        if(departmentid.endsWith(",")){
            departmentid=departmentid.substring(0,departmentid.length()-1);
        }
        String sql="select * from docreceiveunit where id in ("+departmentid+")";
        re.execute(sql);
        while(re.next()){
            departmentname=departmentname+Util.null2String(re.getString("receiveunitname")).trim()+",";
        }
        if(departmentname.endsWith(",")){
            departmentname=departmentname.substring(0,departmentname.length()-1);
        }
        return departmentname;
    }
    public static String getSwDpartmentnameByName(String departmentname){
        log.writeLog("getSwDpartmentnameByName-->"+departmentname);
        RecordSet re=new RecordSet();
        String departmentids="";
        departmentname= Util.null2String(departmentname).trim();
        if("".equals(departmentname)){
            return "";
        }
        if(departmentname.endsWith(",")){
            departmentname=departmentname.substring(0,departmentname.length()-1);
        }
        for(int i=0;i<departmentname.split(",").length;i++){
            String demo=Util.null2String(departmentname.split(",")[i]).trim();
            if("".equals(demo)){
                continue;
            }
            String sql="select * from docreceiveunit where receiveunitname = '"+demo+"'";
            re.execute(sql);
            if(re.next()){
                departmentids=departmentids+Util.null2String(re.getString("id")).trim()+",";
                log.writeLog("departmentids-->"+departmentids);
            }else{
                return "";
            }

        }
        if(departmentids.endsWith(",")){
            departmentids=departmentids.substring(0,departmentids.length()-1);
        }
        return departmentids;
    }

    /*
        获取事项标题
     */
    public String getTitlebyId(String rwid){
        RecordSet re=new RecordSet();
        String url="";
        String sql="select * from uf_dcsxzb where id="+rwid;
        re.execute(sql);
        if(re.next()){
            String wh=Util.null2String(re.getString("wh")).trim();
            String bh=Util.null2String(re.getString("bh")).trim();
            String bt=Util.null2String(re.getString("bt")).trim();

        }
        return url;
    }
    /*
        状态变更  签收日期为 yyyy-MM-dd HH:mm
        根据限时签收日期  @sxqsrq
     */
    public String getQSStatus(String sxqsrq){
        String div="";
        sxqsrq=Util.null2String(sxqsrq).trim();
        if(!"".equals(sxqsrq)){
            //判断当前日期是否超出 限时接收日期
            try{
                SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm");
                long sxqsrqTime= sim.parse(sxqsrq).getTime();
                long currentTime= sim.parse(sim.format(new Date())).getTime();
                if(sxqsrqTime>=currentTime){
                    //div="<div class=\"sw_duban_zt\" style=\""+DubUtil.backgroundcolor[0]+"\"></div>";
                    div="<div class=\"fav\"   style=\"width: 30px;height: 30px;background-repeat: no-repeat;background-image: url('"+DubUtil.backgroundcolorpng[0]+"');background-size: 80%;\">" +
                    "<span><ul id=\"navFav\"> </ul></span>" + "</div>";
                }else{
                    //div="<div class=\"sw_duban_zt\" style=\""+DubUtil.backgroundcolor[2]+"\"></div>";
                    div="<div class=\"fav\"   style=\"width: 30px;height: 30px;background-repeat: no-repeat;background-image: url('"+DubUtil.backgroundcolorpng[2]+"');background-size: 80%;\">" +
                            "<span><ul id=\"navFav\"> </ul></span>" + "</div>";
                }
            }catch(Exception e){

            }

        }else{
            return "";
        }
        return div;
    }
    /*
        获取下拉框的值
        字段名称  @field
        表名     @tablename
        值      @value
     */
    public String getSelectnameByValue(String value,String tablename,String field){
        String selectname="";
        RecordSet re=new RecordSet();
        String sql="select c.selectname from workflow_bill a,workflow_billfield b,workflow_selectitem c where a.id=b.billid and a.tablename='"+tablename+"'" +
                   " and b.id=c.fieldid and b.fieldname='"+field+"' and c.selectvalue='"+value+"'";
        re.execute(sql);
        while(re.next()){
            selectname=Util.null2String(re.getString("selectname"));
        }
        return selectname;
    }
    /*
       督办任务 标题设置  编号+文号+ 标题
     */
    public String getDubanTitle(String rwid){
        RecordSet re=new RecordSet();
        rwid=Util.null2String(rwid).trim();
        String sql="select wh,bh,bt from uf_dcsxzb where id="+rwid;
        re.execute(sql);
        String bh="";//编号
        String bt="";//标题
        String wh="";//文号
        while(re.next()){
            bh=re.getString("bh");
            bt=re.getString("bt");
            wh=re.getString("wh");
        }
        String title=bh+"  "+wh+"</br>"+bt;
        String url="<a title=\""+title+"\" href=\"javascript:void(0)\" onclick=\"javaScript:winopenSlideModal(true,'/spa/cube/index.html#/main/cube/card?type=0&modeId="+DubUtil.modeId+"&formId="+DubUtil.formId+"&billid="+rwid+"&opentype=2&customid="+DubUtil.customid+"&viewfrom=fromsearchlist&dbviewtype=3');event.stopPropagation();\" class=\"autoWrap\">"+title+"</a>";
        return url;
    }
    /*
       督办任务 标题设置  编号+文号+ 标题
     */
    public String getDubanTitleTz(String rwid){
        RecordSet re=new RecordSet();
        rwid=Util.null2String(rwid).trim();
        String sql="select wh,bh,bt from uf_dcsxzb where id="+rwid;
        re.execute(sql);
        String bh="";//编号
        String bt="";//标题
        String wh="";//文号
        while(re.next()){
            bh=re.getString("bh");
            bt=re.getString("bt");
            wh=re.getString("wh");
        }
        String title=bh+"  "+wh+"\n"+bt;
        String url="<a title=\""+title+"\" href=\"javascript:void(0)\" onclick=\"javaScript:winopenSlideModal(true,'/spa/cube/index.html?type=3#/main/cube/card?type=0&modeId="+DubUtil.modeId+"&formId="+DubUtil.formId+"&billid="+rwid+"&opentype=2&customid="+DubUtil.customid+"&viewfrom=fromsearchlist&dbviewtype=3');event.stopPropagation();\" class=\"autoWrap\">"+title+"</a>";
        return url;
    }
    /*
      督办任务 标题设置  编号+文号+ 标题
    */
    public String getDubanTitleJTz(String tzid){
        RecordSet re=new RecordSet();
        tzid=Util.null2String(tzid).trim();
        String sql="select dcwh,bt,sffkjh from uf_jcdctz where id="+tzid;
        re.execute(sql);
        String bh="";//编号
        String bt="";//标题
        String wh="";//文号
        String sffkjh="";//是否反馈计划
        while(re.next()){

            bt=re.getString("bt");
            wh=re.getString("dcwh");
            sffkjh=Util.null2String(re.getString("sffkjh")).trim() ;
        }
        String title=bt;
        String url="<a title=\""+title+"\" href=\"javascript:void(0)\" onclick=\"javaScript:winopenSlideModal(true,'/spa/cube/index.html?dbtype=2&sffkjh="+sffkjh+"#/main/cube/card?type=0&modeId="+DubUtil.jcmodeId+"&formId="+DubUtil.jcformId+"&billid="+tzid+"&opentype=2&customid="+DubUtil.customid+"&viewfrom=fromsearchlist&dbviewtype=3');event.stopPropagation();\" class=\"autoWrap\">"+title+"</a>";
        return url;
    }
    /*
        获取交办时间
     */
     public String getBjTime(String param1,String param2){
         String sjjbrq="";
         RecordSet re=new RecordSet();
         String sql="select bjsj from uf_dbjblb where ssrwid='"+param2+"' order by bjsj desc ";
         re.execute(sql);
         while(re.next()){
             sjjbrq=Util.null2String(re.getString("bjsj"));
         }
         return sjjbrq;
     }
     /*
        获取立项任务是否是 办理中或者 已办结
      */
    public  String getRwStatus(String field,String param1){
        RecordSet re=new RecordSet();
        String status="";
        String sql="select 1 from  uf_dcsxzb a where a.id='"+param1+"' and exists (select 1 from uf_dbjblb b where a.id=b.id and isnull(b.zt,-1)  in (-1,0,1))";
        re.execute(sql);
        if(re.next()){
            status="办理中";
        }else{
            status="已办结";
        }
        return status;
    }
    /*
            决策督察是否可选
     */
    public boolean disabledCheckbox(String id){
        RecordSet re=new RecordSet();
        String sql="select * from uf_jcdcrw where id="+id;
        //log.writeLog(sql);
        re.execute(sql);
        if(re.next()){
            String zt=Util.null2String(re.getString("zt")).trim();
            if("".equals(zt)||"0".equals(zt)){
                return true;
            }else{
                return false;
            }
        }
        return false;
    }
    /*
        转换成便签
     */
    public String getBqk(String bqid){
        String str="";
        RecordSet re=new RecordSet();
        bqid=Util.null2String(bqid).trim();
        if(bqid.endsWith(",")){
            bqid=bqid.substring(0,bqid.length()-1);
        }
        String sql ="select * from uf_bqk where id in ("+bqid+")";
        re.execute(sql);
        while(re.next()){
            String demo="";
          String wzys="";
          String bjys="";
          String bqys="";
          String mc=Util.null2String(re.getString("mc")).trim();
          wzys=Util.null2String(re.getString("wzys")).trim();
          bjys=Util.null2String(re.getString("bjys")).trim();
          bqys=Util.null2String(re.getString("bqys")).trim();
          if("".equals(wzys)){
               wzys="#fff";
          }
          if("".equals(bjys)){
                bjys="#ff5500";
          }
          if("".equals(bqys)){
                bqys="#ff5500";
          }
            demo=mc+","+wzys+","+bjys+","+bqys+"$";
            str=str+demo;
        }
        if(str.endsWith("$")){
            str=str.substring(0,str.length()-1);
        }
        return str;
    }
    /*
        附件凭借
     */
    public String pingZwFj(String fj,String zw){
        String xgfj="";
        //log.writeLog(fj+"--"+zw);
        fj=Util.null2String(fj).trim();
        zw=Util.null2String(zw).trim();
        if(!"".equals(fj)){
            if(fj.endsWith(",")){
                fj=fj.substring(0,fj.length()-1);
            }
            xgfj=xgfj+fj+",";
        }
        if(!"".equals(zw)){
            if(zw.endsWith(",")){
                zw=zw.substring(0,zw.length()-1);
            }
            xgfj=xgfj+zw+",";
        }
        if(xgfj.endsWith(",")){
            xgfj=xgfj.substring(0,xgfj.length()-1);
        }
        return xgfj;
    }
}
